﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Fashion.Models;

namespace Fashion.ViewModels
{
    public class UserViewModel
    {
        private FashionEntities1 FashionDB = new FashionEntities1();

        public User currentUser { get; set; }
        public int pendingOrder { get; set; }
        public int availableCoupon { get; set; }

        public UserViewModel()
        {
            this.currentUser = null;
            this.pendingOrder = 0;
            this.availableCoupon = 0;
        }
    
        public UserViewModel(User user)
        {
            this.currentUser = user;
            getAvailableCoupon(user.UserID);
            getPendingOrder(user.UserID);
        }

        protected void getPendingOrder(int userID)
        {
            var orderModel = from orders in FashionDB.Orders
                             where orders.UserID == userID && orders.CurrentStatus == "pending"
                             select orders;

            this.pendingOrder = orderModel.Count();
        }

        protected void getAvailableCoupon(int userID)
        {
            var couponModel = from coupons in FashionDB.UserCoupons
                              where coupons.UserID == userID
                              select coupons;

            this.availableCoupon = couponModel.Count();
        }
    }
}